﻿
@page
@model AdminUI.Pages.BaseData.AreaModel
@{
    var F = Html.F();
}

@section body {

    <f:RegionPanel ID="RegionPanel1" IsFluid="true" CssClass="blockpanel" ShowBorder="false" Margin="10" IsViewPort="true">
        <Regions>
            <f:Region ID="Region1" ShowBorder="false" ShowHeader="false" RegionPosition="Left" BodyPadding="0 5 0 0" Width="260" Layout="Fit">
                <Items>
                    <f:Form ID="Panel1" IsFluid="true" ShowBorder="true" ShowHeader="false" AutoScroll="true" Layout="VBox" BodyPadding="5">
                        <Items>
                            <f:Tree ID="Tree1" IsFluid="true" MinHeight="500" ShowHeader="false" ShowBorder="false" Nodes="@(TreeNode[])ViewBag.TreeNodeData">
                                <Listeners>
                                    <f:Listener Event="nodeclick" Handler="onTree1NodeClick"></f:Listener>
                                </Listeners>
                            </f:Tree>
                        </Items>
                    </f:Form>
                </Items>
            </f:Region>
            <f:Region ID="Region2" ShowBorder="false" ShowHeader="false" RegionPosition="Center" Layout="VBox" BoxConfigAlign="Stretch">
                <Items>
                    <f:Grid ID="Grid1" BoxFlex="1" ShowBorder="true" ShowHeader="false" EnableTextSelection="true" EnableColumnLines="true" DataIDField="AreaID" DataTextField="AreaName"
                            EnableCheckBoxSelect="true" EnableMultiSelect="false" DataSource="@ViewBag.NodeList">
                        <Toolbars>
                            <f:Toolbar ID="Toolbar1" ToolbarAlign="Right" ItemSpace="1">
                                <Items>
                                    <f:Button ID="btnAdd" IconAlign="Left" EnableDefaultState="false" IconFont="_Plus" Text="新增" OnClientClick="onAddClick();"></f:Button>
                                    <f:ToolbarSeparator></f:ToolbarSeparator>
                                    <f:Button ID="btnEdit" IconAlign="Left" EnableDefaultState="false" IconFont="_Edit" Text="编辑" OnClientClick="onEditClick();"></f:Button>
                                    <f:ToolbarSeparator></f:ToolbarSeparator>
                                    <f:Button ID="btnDelete" IconAlign="Left" EnableDefaultState="false" IconFont="TrashO" Text="删除" OnClientClick="onDeleteClick();"></f:Button>
                                  @*  <f:ToolbarSeparator></f:ToolbarSeparator>
                                    <f:Button ID="btnChangeEnableUsers" IconAlign="Left" EnableDefaultState="false" IconFont="_Tag" Text="状态">
                                        <Menu>
                                            <f:MenuButton ID="btnEnableUsers" Text="启用" OnClientClick="onEnableClick();"></f:MenuButton>
                                            <f:MenuButton ID="btnDisableUsers" Text="禁用" OnClientClick="onDisableClick();"></f:MenuButton>
                                        </Menu>
                                    </f:Button>*@
                                    <f:ToolbarSeparator></f:ToolbarSeparator>
                                    <f:Button ID="btnRefresh" IconAlign="Left" EnableDefaultState="false" IconFont="_Refresh" Text="刷新" OnClientClick="onRefreshClick();"></f:Button>
                                    <f:ToolbarFill ID="ToolbarFill1"></f:ToolbarFill>
                                    <f:DropDownList ID="ddlCondition" SelectedValue="" Width="150">
                                        <f:ListItem Text="== 请选择条件 ==" Value="" />
                                        <f:ListItem Text="区域ID" Value="AreaID" />
                                        <f:ListItem Text="区域名称" Value="AreaName" />
                                    </f:DropDownList>
                                    <f:TriggerBox ID="ttbSearch" ShowLabel="false" EmptyText="请输入搜索关键字" TriggerIcon="Search" OnTriggerClick="@Url.Handler("Grid_DoAction")" OnTriggerClickFields="Region2"
                                                  OnTriggerClickParameter1="@(new Parameter("actionType", "search", ParameterMode.String))"
                                                  OnTriggerClickParameter2="@(new Parameter("searchText", "F.ui.ttbSearch.getValue()"))"
                                                  OnTriggerClickParameter3="@(new Parameter("searchCondition", "F.ui.ddlCondition.getValue()"))">
                                    </f:TriggerBox>
                                </Items>
                            </f:Toolbar>
                        </Toolbars>
                        <Columns>
                            <f:RowNumberField HeaderText="#" TextAlign="Center" />
                            <f:RenderField HeaderText="区域ID" DataField="AreaID" FieldType="Int" QuickSortField="true" Width="80" TextAlign="Center" />
                            <f:RenderField HeaderText="区域名称" DataField="AreaName" Width="160" />
                            <f:RenderField HeaderText="简称" DataField="ShortName" Width="70" />
                            <f:RenderField HeaderText="行政级别" DataField="AreaLevel" FieldType="Int" RendererFunction="renderLevel" Width="100" TextAlign="Left" />
                            <f:RenderField HeaderText="首字母" DataField="FirstLetter" Width="70" TextAlign="Center" />
                            <f:RenderField HeaderText="缩写" DataField="ShortSpell" Width="120" />
                            <f:RenderField HeaderText="上级ID" DataField="ParentID" FieldType="Int" RendererFunction="renderParent" Width="160" TextAlign="Left" />
                            <f:RenderField HeaderText="排序" DataField="SortFlag" FieldType="Int" Width="60" TextAlign="Center" />
                            @*<f:RenderCheckField HeaderText="启用" DataField="IsEnable" RenderAsStaticField="true" Width="50" TextAlign="Center" />*@
                            <f:RenderField HeaderText="备注" DataField="Memo" Width="200" ExpandUnusedSpace="true" />
                        </Columns>
                    </f:Grid>
                </Items>
            </f:Region>
        </Regions>
    </f:RegionPanel>

    <f:Window ID="Window1" IsModal="true" Hidden="true" Target="Top" EnableResize="true" EnableMaximize="true" EnableIFrame="true" Width="700" Height="350">
        <Listeners>
            <f:Listener Event="close" Handler="onWindowClose('refresh');"></f:Listener>
        </Listeners>
    </f:Window>

}


@section script {

    <script src="~/res/js/grid.js"></script>
    <script>
        function onWindowClose(actionType, actionParams) {
            var params = {
                nodeId: getNodeId()
            };

            // 加入扩展参数
            if(actionType) {
                params.actionType = actionType;
            }
            if(actionParams) {
                $.extend(params, actionParams);
            }

            // 触发后台事件
            F.doPostBack('@Url.Handler("Grid_DoAction")', 'RegionPanel1', params);
        }

        function getNodeId() {
            var nodeId = 0;
            var nodeData = F.ui.Tree1.getSelectedNode(true);
            if (nodeData) {
                nodeId = nodeData.id;
            }
            return nodeId;
        }

        function onAddClick(event) {
            var nodeId = 0;
            var nodeText = "请选择上级";
            var nodeData = F.ui.Tree1.getSelectedNode(true);
            if (nodeData) {
                nodeId = nodeData.id;
                nodeText = nodeData.text;
            }

            var path = "/BaseData/AreaAdd?nodeId=" + nodeId + "&nodeText=" + nodeText;
            F.ui.Window1.show(path, '新增行政区域');
        }

        function onEditClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要修改的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/AreaEdit?id=" + selectedRow;
            //showNotify(path);
            F.ui.Window1.show(path, '修改行政区域');
        }

        function onDeleteClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要删除的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要删除所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Region2', {
                        actionType: 'delete',
                        nodeId: getNodeId(),
                        selectedIDs: selectedRows
                    });
                }
            });
        }
        function onEnableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要启用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要启用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Region2', {
                        actionType:'enable',
                        nodeId: getNodeId(),
                        selectedIDs: selectedRows
                    });
                }
            });
        }

        function onDisableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要禁用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要禁用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Region2', {
                        actionType:'disable',
                        nodeId: getNodeId(),
                        selectedIDs: selectedRows
                    });
                }
            });
        }
        function onRefreshClick() {
            var grid1 = F.ui.Grid1;
            var selectedRows = grid1.getSelectedRows();
            F.doPostBack('@Url.Handler("Grid_DoAction")', 'Region2', {
                actionType: 'refresh',
                nodeId: getNodeId(),
                selectedIDs: selectedRows
            });
        }

        function onTree1NodeClick(event, nodeId) {
            var tree = this;
            var nodeData = tree.getNodeData(nodeId);

            // 触发后台事件
            F.doPostBack('@Url.Handler("Tree1_NodeClick")', 'Grid1', {
                nodeId: nodeId,
                nodeText: nodeData.text
            });
        }

        function renderLevel(value, params) {
            switch (value) {
                case 1:
                    return "省/自治区";
                case 2:
                    return "地级市";
                case 3:
                    return "县/县级市/区";
                default:
                    return "乡镇";
            }
        }

        //HTML格式化
        function renderParent(value, params) {
            var nodeData = F.ui.Tree1.getSelectedNode(true);

            if (nodeData) {
                return F.formatString('{0}-{1}', value, nodeData.text);
            } else {
                return '0-中国';
            }
        }


    </script>
}